#include <iostream>
#include "stack.h"
using namespace std;

int ack(int m, int n) {
    Stack s1;
    Stack s2;
    s1.push(m);
    s2.push(n);
    while (!s1.empty()) {
        while(m != 0) {
            if (n == 0) {
                m = m - 1;
                n = 1;
                s1.push(m);
                s2.push(1);
                }
            else {
                n = n - 1;
                s1.push(m - 1);
                s2.push(-1);
                }
            }
        n = n + 1;
        while (!s1.empty() && s2.top() != -1) {
            s1.pop();
            s2.pop();
            }
        if (!s1.empty()) {
            m = s1.top();
            s2.pop();
            s2.push(n);
            }
        }
    return n;
    }
int main() {
    cout << ack(2, 1);
    return 0;
    }
